import errorHandler from "@/utils/error-handle";
import type { RequestOptionsInit } from 'umi-request';
import { RequestConfig } from '@/.umi/plugin-request/request'

// 请求拦截
const authHeaderInterceptor = (url: string, options: RequestOptionsInit) => {
  // const authHeader = { Authorization: 'Bearer xxxxxx' };// 配置统一token使用
  // console.log("请求前拦截：", url);
  // console.log("请求前拦截1：", `${url}`);
  return {
    url: `${url}`,
    options: { ...options, interceptors: true, },// headers: authHeader 配置统一token使用
  };
};
// 响应后拦截
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const demoResponseInterceptors = (response: Response, options: RequestOptionsInit) => {
  // console.log(response);
  return response;
};
// 配置request
export const request: RequestConfig = {
  // prefix: process.env.NODE_ENV === "production" ? 'http://192.168.31.166:10060' : 'http://192.168.31.166:10060',  // 监测开发环境
  prefix: process.env.NODE_ENV === "production" ? 'http://127.0.0.1:11000' : 'http://127.0.0.1:11000',  // 监测开发环境
  // credentials: 'same-origin',
  mode:'cors',
  errorHandler,
  requestInterceptors: [authHeaderInterceptor],
  responseInterceptors: [demoResponseInterceptors],
  middlewares: [],
};